package com.douziit.meilianoa.base.redis;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

/**
 * 生成系统redis key
 */
@Slf4j
public class RedisKeyGenerate {
    private static final String UND = "_";
    /**
     * 获取：协议管理-数据组Key
     * @param typeId
     * @param modelId
     * @return
     */
    public static String getCpDataGroupKey(String typeId,String modelId){
        log.info("getCpDataGroupKey>>>>>>>>>typeId:【"+typeId+"】>>>>>>>>>>>>modelId:【"+modelId+"】");
        if (StringUtils.isBlank(typeId)
                &&  StringUtils.isBlank(modelId)) {
            log.warn("typeId，modelId不能为空>>>>>>>>>typeId:【"+typeId+"】>>>>>>>>>>>>modelId:【"+modelId+"】");
           return null;
        }
        //TypeId:12_ModelId:11
       String key =  RedisConstant.DEVICE_TYPE_ID_PREFIX.concat(typeId).concat(UND).concat(RedisConstant.DEVICE_MODEL_ID_PREFIX ).concat(modelId);
        return key;
    }

    /**
     * 获取：协议管理-数据位Key
     * @param groupId
     * @return
     */
    public static String getCpDataBitGroupKey(int groupId){
        log.info("getCpDataGroupKey>>>>>>>>>groupId:【"+groupId+"】");
        if (groupId <= 0) {
            log.warn("groupId不能为空>>>>>>>>>groupId:【"+groupId+"】");
            return null;
        }
        String key =  RedisConstant.DEVICE_DATA_BIT_ID_PREFIX.concat(String.valueOf(groupId));
        return key;
    }

    /**
     * 获取：协议管理-状态位Key
     * @param groupId
     * @return
     */
    public static String getCpDataStatusGroupKey(int groupId){
        log.info("getCpDataGroupKey>>>>>>>>>groupId:【"+groupId+"】");
        if (groupId <= 0) {
            log.warn("groupId不能为空>>>>>>>>>groupId:【"+groupId+"】");
            return null;
        }
        String key =  RedisConstant.DEVICE_DATA_STATUS_ID_PREFIX.concat(String.valueOf(groupId));
        return key;
    }

    /**
     * 获取：协议管理-报警位Key
     * @param groupId
     * @return
     */
    public static String getCpDataAlarmGroupKey(int groupId){
        log.info("getCpDataGroupKey>>>>>>>>>groupId:【"+groupId+"】");
        if (groupId <= 0) {
            log.warn("groupId不能为空>>>>>>>>>groupId:【"+groupId+"】");
            return null;
        }
        String key =  RedisConstant.DEVICE_DATA_ALARM_ID_PREFIX.concat(String.valueOf(groupId));
        return key;
    }

    /**
     * 获取：协议管理-参数项Key
     * @param groupId
     * @return
     */
    public static String getCpDataParamGroupKey(int groupId){
        log.info("getCpDataGroupKey>>>>>>>>>groupId:【"+groupId+"】");
        if (groupId <= 0) {
            log.warn("groupId不能为空>>>>>>>>>groupId:【"+groupId+"】");
            return null;
        }
        String key =  RedisConstant.DEVICE_DATA_PARAM_ID_PREFIX.concat(String.valueOf(groupId));
        return key;
    }

    /**
     * 获取：协议管理-指令项Key
     * @param groupId
     * @return
     */
    public static String getCpDataInstructionsGroupKey(int groupId){
        log.info("getCpDataGroupKey>>>>>>>>>groupId:【"+groupId+"】");
        if (groupId <= 0) {
            log.warn("groupId不能为空>>>>>>>>>groupId:【"+groupId+"】");
            return null;
        }
        String key =  RedisConstant.DEVICE_DATA_INSTRUCTIONS_ID_PREFIX.concat(String.valueOf(groupId));
        return key;
    }

  public static void main(String[] args) {
    System.out.println(RedisKeyGenerate.getCpDataGroupKey("2222","3333"));
  }
}
